home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Gamer Resource Kit / Hardcore Gamer Resource Kit - Disc 3.iso / screensavers / saver17.zip / VoodooLights / Sources / cell_tp8.c < prev    next >
C/C++ Source or Header  |  1997-07-24  |  2KB  |  117 lines

  1. /*------------------------------------------------------/
  2. /                                                        /
  3. /    Copyright 1997, SΘrgio Durte <smd@di.fct.unl.pt>    /
  4. /                                                        /
  5. /------------------------------------------------------*/
  6.  
  7. #include <stdlib.h>
  8. #include <math.h>
  9. #include <glide.h>
  10.  
  11. #include "defines.h"
  12. #include "mat.h"
  13. #include "rgb.h"
  14. #include "tex.h"
  15. #include "cam.h"
  16. #include "cell.h"
  17. #include "cell_util.h"
  18. #include "cell_tp2.h"
  19. #include "cell_tp8.h"
  20. #include "cell_tp9.h"
  21.  
  22. static Bool first_init = True ;
  23. static GrMipMapId_t tp8_texture_src ;
  24.  
  25.  
  26. static void tp8_acc_cell(Cell *c) 
  27. {
  28.     XYZ    d ;
  29.     Cell **p ;
  30.     int n ;
  31.  
  32.     mat_scalev( -0.2, & c->pos, & c->acc ) ;
  33.  
  34.     p = cell_get_cells_by_type( CellType2, & n ) ;
  35.     cutl_closest_interaction( c, p, n, 4000.0, 1.0 ) ;
  36.  
  37.     p = cell_get_cells_by_type( CellType8, & n ) ;
  38.     cutl_closest_interaction( c, p, n, -14000.0, 2.0 ) ;
  39. }
  40.  
  41. static void tp8_reproduce_cell( Cell *c) 
  42. {
  43.     int i ;
  44.  
  45.     for( i = 0 ; i < 2 ; i++ ) {
  46.         Cell *son = ctp9_Constructor( NULL ) ;
  47.         Float a, b, r ;
  48.         XYZ d ;
  49.  
  50.         a = rnd() * 2 * PI ;
  51.         b = rnd() * PI ;
  52.  
  53.         r = 1.0 * cos( b ) ;
  54.         son->pos.x = c->pos.x + r * cos( a ) ;
  55.         son->pos.y = c->pos.y + r * sin( a ) ;
  56.         son->pos.z = c->pos.z + 1.0 * sin( b ) ;
  57.         mat_scalev( 0.95, & c->vel, & son->vel ) ;
  58.         mat_subv( & son->pos, & c->pos, & d ) ;
  59.         mat_combv( 18.0, & d, & son->vel, & son->vel ) ;
  60.     }
  61. }
  62.  
  63. void tp8_set_glide_state( void )
  64. {
  65.     if( first_init ) {
  66.         first_init = False ;
  67.         tp8_texture_src = tex_InitTexture("flare1.3df") ;
  68.     }    
  69.  
  70.     tex_SetTexSource( tp8_texture_src ) ;
  71.     grTexCombineFunction(GR_TMU0, GR_TEXTURECOMBINE_DECAL ) ;
  72.     guColorCombineFunction( GR_COLORCOMBINE_TEXTURE_TIMES_ITRGB ) ;
  73.     guAlphaSource( GR_ALPHASOURCE_ITERATED_ALPHA );    
  74.     grAlphaBlendFunction( GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ONE, GR_BLEND_ZERO );
  75. }
  76.  
  77. Cell *ctp8_Constructor( Cell *dad )
  78. {
  79.  
  80.   Cell *c = cell_Constructor( CellType8 ) ;
  81.  
  82.   c->max_speed = 60.0 ;
  83.  
  84.   c->age = 10.0 ;
  85.   c->dad = dad ;
  86.  
  87.   c->max_chld = 1 ;
  88.   c->p_chld = 0.05 * rnd() + 0.05 ;
  89.  
  90.   c->adulthood = 20.0 ;
  91.  
  92.   cutl_random_pos( 950.0, c ) ;
  93.  
  94.   c->size = 8.0 ;
  95.  
  96.   c->color.r = 255.0 ;
  97.   c->color.g = 220.0 ;
  98.   c->color.b = 255.0 ;
  99.   c->color.a = 1.0 ;
  100.  
  101.   c->sparkle = 1.0 ;
  102.  
  103.   c->acc_cell = tp8_acc_cell ;
  104.   c->reproduce_cell = tp8_reproduce_cell ;
  105.   return c ;
  106. }  
  107.     
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.     
  116.  
  117.